CSE HTML Validator Standard/Professional v6.01 Documentation
[ Home | Download | Order | Support ]
One of the best ways to learn and explain is by example. This page contains some examples about how to use the template tool that is included with CSE HTML Validator.
The following may appear in an HTML document that may be processed by this tool:
<!-- TEMPLATESTART
TEMPLATE=c:\htmlval\htmltemplates\template1.txt
GRAPHIC=/images/logo.gif
AUTHOR=Albert Wiersch
EMAIL=al@htmlvalidator.com
-->
(The template file is inserted here (the file defined by the symbol TEMPLATE) with symbols replaced by values defined above. Any previous text that is located here is completely removed and replaced by the template file.)
<!-- TEMPLATEEND -->
By running the template tool on an HTML document containing the above, HTML Validator uses the file specified by TEMPLATE to insert text from that file into the space between the two comments (after the line --> and before the line <!-- TEMPLATEEND -->). The template file may include symbols (examples of symbols: TEMPLATE, GRAPHIC, AUTHOR, etc.) so that portions of the template file are replaced with the symbol values (examples of symbol values: /images/logo.gif, Albert Wiersch, etc.) when the template is inserted into the HTML document. To indicate that a symbol should be replaced with its value when inserting into the document from a template, specify the symbol in the following format in the template: $"SYMBOL". NOTE: the symbol must appear within double quotes (exclude the dollar sign in the double quotes) and must follow immediately after the dollar sign! Examples from the above include $"GRAPHIC", $"AUTHOR", etc. To actually include one dollar sign, include $$ (two dollar signs) in the template file. NOTE: New to v4.51 Pro, you do not have to escape the dollar sign unless it is followed by a double quote character.
Assume the following document is c:\html\hobbies.html:
<html>
<head>
<title>My Hobbies</title>
</head>
<body>
(The body of the HTML document can go here. This text is not changed by the template tool because it is not within the body of the following comment section.)
<!-- TEMPLATESTART
TEMPLATE=c:\html\footer1.txt
NAME=John Doe
-->
(Any text here is replaced by the template file c:\html\footer1.txt.)
<!-- TEMPLATEEND -->
Assume the following document is the template footer.txt:
<p><hr>
Content by $"NAME".
</body>
</html>
Now, when you process hobbies.html with the template tool, it will be changed to the following:
<html>
<head>
<title>My Hobbies</title>
</head>
<body>
(The body of the HTML document can go here. This text is not changed by the template tool because it is not within the body of the following comment section.)
<!-- TEMPLATESTART
TEMPLATE=c:\html\footer1.txt
NAME=John Doe
-->
<p><hr>
Content by John Doe.
</body>
</html>
<!-- TEMPLATEEND -->
Notice the comments in hobbies.html. By using the template tool on this document, the text file specified by TEMPLATE (which is c:\html\footer1.txt) is inserted between the lines --> and <!--TEMPLATEEND -->. In addition, anywhere in this document where $"NAME" appears, John Doe is inserted instead. You are not limited to just NAME, however; you may define up to 50 symbols (NAME and TEMPLATE are symbols in the above example).
Anytime you want this HTML document to have a different footer, just change the template file (c:\html\footer1.txt) and use the template tool on all the documents that need updating. You can use the tool many times on the same document; each time it's used, the old template file is removed from the HTML document and replaced with a new one, so you don't have to do anything to your HTML document before using the template tool on it again. You can even set it up so that you just need to right-click on your HTML document from Microsoft Explorer and then choose one of the menu items from the pop-up menu in order to use the tool on the selected files. Or even better, just drag all the files to be processed onto HTML Validator. This makes it easy to quickly process one or more HTML documents with a few mouse clicks.
The advantage of using this tool is that by changing the template file, and then using the template tool on all the HTML documents using that template, you can easily change ALL of your HTML documents in far less time than it may take you to individually go through them and change each one manually! Furthermore, it is not just a simple text file insertion, as you can assign symbols in each HTML document so that the text inserted into each HTML document will be specific for that document. It also does not require any extra server processing or parsing each time a document is viewed because your pages remain static.
For more examples you can view the source of many of CSE HTML Validator's pages to see how the template tool has been used to greatly reduce the maintenance time of this site.
This is an example about how to use the template tool to insert the current date into your document. Every time you want to update the date, you will have to process the document with the template tool. To change the default date format, please see the information about CURRENTDATE.
Insert the following into your document where you want the date inserted:
<!-- TEMPLATESTART
TEMPLATE=c:\html\date.txt
-->
<!-- TEMPLATEEND -->
The file c:\html\date.txt should contain something like:
<p>Document last modified on $"CURRENTDATE".
That's it! Process the document with the template tool and the template file with the current date will be inserted.
The template tool now has built-in symbols.
To change the format of the time string, specify a symbol named TIMEFORMAT that contains a format picture string.
[From the Windows API Programmer's Reference] Use the following elements to construct a format picture string. If you use spaces to separate the elements in the format string, these spaces will appear in the same location in the output string. The letters must be in uppercase or lowercase as shown (for example, "ss", not "SS"). Characters in the format string that are enclosed in single quotation marks will appear in the same location and unchanged in the output string.
For example, to get the time string "11:29:40 PM", use the following picture string: "hh':'mm':'ss tt".
To change the format of the date string, specify a symbol named DATEFORMAT that contains a format picture string.
[From the Windows API Programmer's Reference] Use the following elements to construct a format picture string. If you use spaces to separate the elements in the format string, these spaces will appear in the same location in the output string. The letters must be in uppercase or lowercase as shown in the table (for example, "MM" not "mm"). Characters in the format string that are enclosed in single quotation marks will appear in the same location and unchanged in the output string.
For example, to get the date string "Wed, Aug 31 94", use the following picture string: "ddd',' MMM dd yy".
If format picture strings are not given, defaults are used. The default time and date formats can be changed by changing the value data of the value names DefaultTimeFormat and DefaultDateFormat in the key HKEY_CURRENT_USER\Software\AI Internet Solutions\CSE HTML Validator v4\Validator DLL\Tools to the appropriate format picture string.
You can define a symbol in the following format:
SYMBOLNAME:=FunctionName(Arguments)
Currently, the only supported function is FileContents(). By using this function, you can assign the contents of a file to a symbol name. For example:
DATAFILE:=FileContents("c:\\data\\january.txt")
This will cause $"DATAFILE" to be replaced by the contents of the file c:\data\january.txt when it appears in a template file.
You can also use the + operator to combine the contents of one or more files. For example:
DATAFILE:=FileContents("c:\\data\\january.txt") + FileContents("c:\\data\\february.txt")
Strings can also be used. For example:
DATAFILE:="The january file is:\n"+FileContents("c:\\data\\january.txt") + "\nEnd of file."
Please note that the above examples should be on one line. If any of them are on more than one line, then your browser has wrapped it.
NOTE: The '\' character is an escape character, so two of these characters are needed to specify a '\' character in a string (such as in the filenames above). '\n' is the escape sequence for a new line.
Copyright © 1997-2003 AI Internet Solutions.